Skip to content

ContextLocalSingleton Provider Class #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2021

Conversation

sonthonaxrk
Copy link
Contributor

@sonthonaxrk sonthonaxrk commented Mar 29, 2021

This is just a preliminary example of how I'd switch to using ContextVars. The advantage of ContextVars is that they actually work when using asyncio. I think it might be worth having a ContextLocalSingleton and a ThreadLocalSingleton. Most people will need a ContextLocalSingleton.

Things I need to do here. Please add anything I'm missing :)

  • Add tests
  • Fix the pipeline
  • Add the backported contextvars library to the dependencies so we can support earlier Python 3 versions.
  • Handle Python 2. I think it might make sense to tie the class into the 'async enabled' flag you have.

Thanks for all your work on this library.

@sonthonaxrk
Copy link
Contributor Author

Build is red because of coveralls failing to upload the results.

coveralls run-test: commands[2] | coverage report --rcfile=./.coveragerc
Name                                      Stmts   Miss  Cover
-------------------------------------------------------------
src/dependency_injector/__init__.py           2      0   100%
src/dependency_injector/containers.pyx      343      9    97%
src/dependency_injector/errors.py             2      0   100%
src/dependency_injector/ext/__init__.py       0      0   100%
src/dependency_injector/ext/aiohttp.py       21      0   100%
src/dependency_injector/ext/flask.py         38      2    95%
src/dependency_injector/providers.pxd       173     21    88%
src/dependency_injector/providers.pyx      1731    106    94%
src/dependency_injector/resources.py         25      6    76%
src/dependency_injector/schema.py           147     20    86%
src/dependency_injector/wiring.py           518     26    95%
-------------------------------------------------------------
TOTAL                                      3000    190    94%

@sonthonaxrk sonthonaxrk changed the title Use contextvars ContextLocalSingleton Provider Class Apr 7, 2021
Copy link
Member

@rmk135 rmk135 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Thanks a lot for the contribution. I left some comments, appreciate if you could take a look. Also please target PR to the develop branch.

@sonthonaxrk
Copy link
Contributor Author

@rmk135

I've made the amends and rebased onto dev.

@sonthonaxrk sonthonaxrk changed the base branch from master to develop April 12, 2021 13:36
@sonthonaxrk sonthonaxrk force-pushed the context-vars branch 3 times, most recently from 5efb8c6 to 6523abc Compare April 12, 2021 14:01
@sonthonaxrk
Copy link
Contributor Author

Fixed the pipeline.

@sonthonaxrk sonthonaxrk requested a review from rmk135 April 14, 2021 07:56
@sonthonaxrk
Copy link
Contributor Author

Hey @rmk135 are you still interested in merging this?

@rmk135
Copy link
Member

rmk135 commented Apr 19, 2021

Hey @rmk135 are you still interested in merging this?

Hey @sonthonaxrk , I do. Merging it now :)

@rmk135 rmk135 merged commit 9cb8e60 into ets-labs:develop Apr 19, 2021
@billcrook
Copy link

Just a heads up that there is no documentation of this provider in the main docs

@rmk135
Copy link
Member

rmk135 commented Jan 10, 2022

@billcrook , thanks for the heads up. It's still in my backlog, will prioritize it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants